package com.heima.article.config;

import com.heima.common.dto.User;
import com.heima.common.util.UserThreadLocalUtil;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;


/**
 * 对当前模块所有的Feign请求进行拦截器
 *
 * @author: itheima
 * @create: 2021-07-30 15:17
 * 隐式传参
 */
@Configuration
public class FeignConfig implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate template) {
        User user = UserThreadLocalUtil.get();
        if (user != null) {
            //设置授权头
            template.header("userId", user.getUserId().toString());
            template.header("userName", user.getUserName());
        }
    }
}
